home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / ginganin.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  9KB  |  356 lines

  1. /**************************************************************************
  2.  
  3.                             Ginga NinkyouDen
  4.                             (C) 1987 Jaleco
  5.  
  6.                     driver by Luca Elia (eliavit@unina.it)
  7.  
  8.  
  9. Note:    if MAME_DEBUG is defined, pressing Z with:
  10.  
  11.         Q        shows background
  12.         W        shows foreground
  13.         E        shows frontmost (text) layer
  14.         A        shows sprites
  15.  
  16.         Keys can be used togheter!
  17.  
  18.  
  19. [Screen]
  20.      Visible Size:        256H x 240V
  21.     Dynamic Colors:        256 x 4
  22.     Color Space:        16R x 16G x 16B
  23.  
  24. [Scrolling layers]
  25.     Format (all layers):    Offset:        0x400    0x000
  26.                             Bit:        fedc---- --------    Color
  27.                                         ----ba98 76543210    Code
  28.  
  29.     [Background]
  30.         Size:                8192 x 512    (static: stored in ROM)
  31.         Scrolling:            X,Y            (registers: $60006.w, $60004.w)
  32.         Tiles Size:            16 x 16
  33.         Tiles Number:        $400
  34.         Colors:                $300-$3ff
  35.  
  36.     [Foreground]
  37.         Size:                4096 x 512
  38.         Scrolling:            X,Y            (registers: $60002.w, $60000.w)
  39.         Tiles Size:            16 x 16
  40.         Tiles Number:        $400
  41.         Colors:                $200-$2ff
  42.  
  43.     [Frontmost]
  44.         Size:                256 x 256
  45.         Scrolling:            -
  46.         Tiles Size:            8 x 8
  47.         Tiles Number:        $200
  48.         Colors:                $000-$0ff
  49.  
  50.  
  51. [Sprites]
  52.     On Screen:            256
  53.     In ROM:                $a00
  54.     Colors:                $100-$1ff
  55.     Format:                See Below
  56.  
  57.  
  58. **************************************************************************/
  59. #include "vidhrdw/generic.h"
  60. #include "cpu/m6809/m6809.h"
  61.  
  62. /* Variables only used here */
  63. static struct tilemap *bg_tilemap, *fg_tilemap, *tx_tilemap;
  64. static int layers_ctrl, flipscreen;
  65.  
  66. /* Variables that driver has access to */
  67. unsigned char *ginganin_fgram, *ginganin_txtram, *ginganin_vregs;
  68.  
  69. /* Variables defined in drivers */
  70.  
  71.  
  72. /***************************************************************************
  73.  
  74.   Callbacks for the TileMap code
  75.  
  76. ***************************************************************************/
  77.  
  78.  
  79. /* Background - Resides in ROM */
  80.  
  81. #define BG_GFX (0)
  82. #define BG_NX  (16*32)
  83. #define BG_NY  (16*2)
  84.  
  85. static void get_bg_tile_info(int tile_index)
  86. {
  87.     int code = memory_region(REGION_GFX5)[2*tile_index + 0] * 256 + memory_region(REGION_GFX5)[2*tile_index + 1];
  88.     SET_TILE_INFO(BG_GFX, code, code >> 12);
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /* Foreground - Resides in RAM */
  96.  
  97. #define FG_GFX (1)
  98. #define FG_NX  (16*16)
  99. #define FG_NY  (16*2)
  100.  
  101. static void get_fg_tile_info(int tile_index)
  102. {
  103.     int code = READ_WORD(&ginganin_fgram[2*tile_index]);
  104.     SET_TILE_INFO(FG_GFX, code, code >> 12);
  105. }
  106.  
  107. WRITE_HANDLER( ginganin_fgram_w )
  108. {
  109.     int old_data, new_data;
  110.  
  111.     old_data  = READ_WORD(&ginganin_fgram[offset]);
  112.     COMBINE_WORD_MEM(&ginganin_fgram[offset],data);
  113.     new_data  = READ_WORD(&ginganin_fgram[offset]);
  114.  
  115.     if (old_data != new_data)
  116.         tilemap_mark_tile_dirty(fg_tilemap,offset/2);
  117. }
  118.  
  119.  
  120.  
  121.  
  122. /* Frontmost (text) Layer - Resides in RAM */
  123.  
  124. #define TXT_GFX (2)
  125. #define TXT_NX  (32)
  126. #define TXT_NY  (32)
  127.  
  128. static void get_txt_tile_info(int tile_index)
  129. {
  130.     int code = READ_WORD(&ginganin_txtram[2*tile_index]);
  131.     SET_TILE_INFO(TXT_GFX, code, code >> 12);
  132. }
  133.  
  134. WRITE_HANDLER( ginganin_txtram_w )
  135. {
  136. int old_data, new_data;
  137.  
  138.     old_data  = READ_WORD(&ginganin_txtram[offset]);
  139.     COMBINE_WORD_MEM(&ginganin_txtram[offset],data);
  140.     new_data  = READ_WORD(&ginganin_txtram[offset]);
  141.  
  142.     if (old_data != new_data)
  143.         tilemap_mark_tile_dirty(tx_tilemap,offset/2);
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150. int ginganin_vh_start(void)
  151. {
  152.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_OPAQUE,16,16,BG_NX,BG_NY);
  153.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,16,16,FG_NX,FG_NY);
  154.     tx_tilemap = tilemap_create(get_txt_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,TXT_NX,TXT_NY);
  155.  
  156.     if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  157.         return 1;
  158.  
  159.     fg_tilemap->transparent_pen = 15;
  160.     tx_tilemap->transparent_pen = 15;
  161.  
  162.     return 0;
  163. }
  164.  
  165.  
  166.  
  167.  
  168.  
  169. WRITE_HANDLER( ginganin_vregs_w )
  170. {
  171.     int new_data;
  172.  
  173.     COMBINE_WORD_MEM(&ginganin_vregs[offset],data);
  174.     new_data  = READ_WORD(&ginganin_vregs[offset]);
  175.  
  176.     switch (offset)
  177.     {
  178.         case 0x0 : { tilemap_set_scrolly(fg_tilemap, 0, new_data); } break;
  179.         case 0x2 : { tilemap_set_scrollx(fg_tilemap, 0, new_data); } break;
  180.         case 0x4 : { tilemap_set_scrolly(bg_tilemap, 0, new_data); } break;
  181.         case 0x6 : { tilemap_set_scrollx(bg_tilemap, 0, new_data); } break;
  182.         case 0x8 : { layers_ctrl = new_data; } break;
  183. //        case 0xa : break;
  184.         case 0xc : { flipscreen = !(new_data & 1);    tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0); } break;
  185.         case 0xe : { soundlatch_w(0,new_data);
  186.                      cpu_cause_interrupt(1,M6809_INT_NMI);
  187.                    } break;
  188.  
  189.         default  : {logerror("CPU #0 PC %06X : Warning, videoreg %04X <- %04X\n",cpu_get_pc(),offset,data);}
  190.     }
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. /* --------------------------[ Sprites Format ]----------------------------
  199.  
  200. Offset:            Values:            Format:
  201.  
  202. 0000.w            y position        fedc ba9- ---- ----        unused
  203.                                 ---- ---8 ---- ----        subtract 256
  204.                                 ---- ---- 7654 3210        position
  205.  
  206. 0002.w            x position        See above
  207.  
  208. 0004.w            code            f--- ---- ---- ----        y flip
  209.                                 -e-- ---- ---- ----        x flip
  210.                                 --dc ---- ---- ----        unused?
  211.                                 ---- ba98 7654 3210        code
  212.  
  213. 0006.w            colour            fedc ---- ---- ----        colour code
  214.                                 ---- ba98 7654 3210        unused?
  215.  
  216. ------------------------------------------------------------------------ */
  217.  
  218. static void draw_sprites(struct osd_bitmap *bitmap)
  219. {
  220. int offs;
  221.  
  222.     for ( offs = 0 ; offs < spriteram_size ; offs += 8 )
  223.     {
  224.         int    y        =    READ_WORD(&spriteram[offs + 0]);
  225.         int    x        =    READ_WORD(&spriteram[offs + 2]);
  226.         int    code    =    READ_WORD(&spriteram[offs + 4]);
  227.         int    attr    =    READ_WORD(&spriteram[offs + 6]);
  228.         int    flipx    =    code & 0x4000;
  229.         int    flipy    =    code & 0x8000;
  230.  
  231.         x = (x & 0xFF) - (x & 0x100);
  232.         y = (y & 0xFF) - (y & 0x100);
  233.  
  234.         if (flipscreen)
  235.         {
  236.             x = 240 - x;        y = 240 - y;
  237.             flipx = !flipx;        flipy = !flipy;
  238.         }
  239.  
  240.         drawgfx(bitmap,Machine->gfx[3],
  241.                 code & 0x3fff,
  242.                 attr >> 12,
  243.                 flipx, flipy,
  244.                 x,y,
  245.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  246.  
  247.     }
  248. }
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. void ginganin_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  257. {
  258. int i, offs;
  259. int layers_ctrl1;
  260.  
  261. layers_ctrl1 = layers_ctrl;
  262.  
  263. #ifdef MAME_DEBUG
  264. if (keyboard_pressed(KEYCODE_Z))
  265. {
  266. int msk = 0;
  267. char buf[80];
  268. static int posx,posy;
  269.  
  270.     if (keyboard_pressed(KEYCODE_Q)) { msk |= 0xfff1;}
  271.     if (keyboard_pressed(KEYCODE_W)) { msk |= 0xfff2;}
  272.     if (keyboard_pressed(KEYCODE_E)) { msk |= 0xfff4;}
  273.     if (keyboard_pressed(KEYCODE_A))    { msk |= 0xfff8;}
  274.     if (msk != 0) layers_ctrl1 &= msk;
  275.  
  276. #define SETSCROLL \
  277.     tilemap_set_scrollx(bg_tilemap, 0, posx); \
  278.     tilemap_set_scrolly(bg_tilemap, 0, posy); \
  279.     tilemap_set_scrollx(fg_tilemap, 0, posx); \
  280.     tilemap_set_scrolly(fg_tilemap, 0, posy); \
  281.     sprintf(buf,"B>%04X:%04X F>%04X:%04X",posx%(BG_NX*16),posy%(BG_NY*16),posx%(FG_NX*16),posy%(FG_NY*16)); \
  282.     usrintf_showmessage(buf);
  283.  
  284.     if (keyboard_pressed(KEYCODE_L))    { posx +=8; SETSCROLL }
  285.     if (keyboard_pressed(KEYCODE_J))    { posx -=8; SETSCROLL }
  286.     if (keyboard_pressed(KEYCODE_K))    { posy +=8; SETSCROLL }
  287.     if (keyboard_pressed(KEYCODE_I))    { posy -=8; SETSCROLL }
  288.     if (keyboard_pressed(KEYCODE_H))    { posx = posy = 0;  SETSCROLL }
  289.  
  290. }
  291. #endif
  292.  
  293.  
  294.     tilemap_update(ALL_TILEMAPS);
  295.  
  296.     palette_init_used_colors();
  297.  
  298.  
  299. /* Palette stuff: visible sprites */
  300. {
  301. int color, colmask[16];
  302.  
  303.     int xmin = Machine->drv->visible_area.min_x - 16 - 1;
  304.     int xmax = Machine->drv->visible_area.max_x;
  305.     int ymin = Machine->drv->visible_area.min_y - 16 - 1;
  306.     int ymax = Machine->drv->visible_area.max_y;
  307.  
  308.     int nmax                =    Machine->gfx[3]->total_elements;
  309.     unsigned int *pen_usage    =    Machine->gfx[3]->pen_usage;
  310.     int color_codes_start    =    Machine->drv->gfxdecodeinfo[3].color_codes_start;
  311.  
  312.     for (color = 0 ; color < 16 ; color++) colmask[color] = 0;
  313.  
  314.     for (offs = 0 ; offs < spriteram_size ; offs += 8)
  315.     {
  316.     int x,y,code;
  317.  
  318.         y    =    READ_WORD(&spriteram[offs + 0]);
  319.         y    =    (y & 0xff) - (y & 0x100);
  320.         if ((y < ymin) || (y > ymax))    continue;
  321.  
  322.         x    =    READ_WORD(&spriteram[offs + 2]);
  323.         x    =    (x & 0xff) - (x & 0x100);
  324.         if ((x < xmin) || (x > xmax))    continue;
  325.  
  326.         code    =    (READ_WORD(&spriteram[offs + 4]) & 0x3fff)% nmax;
  327.         color    =    READ_WORD(&spriteram[offs + 6]) >> 12;
  328.  
  329.         colmask[color] |= pen_usage[code];
  330.     }
  331.  
  332.     for (color = 0; color < 16; color++)
  333.     {
  334.         if (colmask[color])
  335.         {
  336.             for (i = 0; i < 16; i++)
  337.                 if (colmask[color] & (1 << i))
  338.                     palette_used_colors[16 * color + i + color_codes_start] = PALETTE_COLOR_USED;
  339.         }
  340.     }
  341.  
  342. }
  343.  
  344.     if (palette_recalc())    tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  345.  
  346.     tilemap_render(ALL_TILEMAPS);
  347.  
  348.     if (layers_ctrl1 & 1)    tilemap_draw(bitmap, bg_tilemap,  0);
  349.     else                    osd_clearbitmap(Machine->scrbitmap);
  350.  
  351.     if (layers_ctrl1 & 2)    tilemap_draw(bitmap, fg_tilemap,  0);
  352.     if (layers_ctrl1 & 8)    draw_sprites(bitmap);
  353.     if (layers_ctrl1 & 4)    tilemap_draw(bitmap, tx_tilemap, 0);
  354.  
  355. }
  356.